<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico"/>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/common.css">
    

    <link rel="stylesheet" href="../../layui/extend/dtree.css">
    <link rel="stylesheet" href="../../layui/extend/font/dtreefont.css">
    <link rel="stylesheet" href="../../layui/extend/formSelects-v4.css">
</head>
<body>
    <div class="yadmin-body animated fadeIn">
        <form action="" id="userInfo"class="layui-form layui-form-pane">
            <div class="layui-form-item">
                <label for="name" class="layui-form-label">
                    用户名称
                </label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" value=""
                           lay-verify="required" lay-vertype="tips"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label for="account" class="layui-form-label">
                    邮箱（登录用）
                </label>
                <div class="layui-input-block">
                    <input type="text" id="account" name="account"
                           lay-verify ="required|email" lay-vertype="tips"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <!-- 编辑时不显示密码框 -->
            <div class="layui-form-item">
                <label for="password" class="layui-form-label">
                    用户密码
                </label>
                <div class="layui-input-block">
                    <input type="password" id="password" name="password"
                           lay-verify="required" lay-vertype="tips"
                           autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item" pane="">
                <label class="layui-form-label">
                    性别
                </label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="0" title="男" checked="checked">
                    <input type="radio" name="sex" value="1" title="女">
                </div>
            </div>

            <div class="layui-input-block" style="margin-left:0;text-align:center;">
                <!--<input type="hidden" id="deptId" name="deptId" value="">-->
                <!--<input type="hidden" id="userId" name="userId" value="">-->
                <button class="layui-btn layui-btn-normal btn-w100" lay-submit lay-filter="search">增加</button>
            </div>
        </form>

    </div>

    <script src="../../layui/layui.js"></script>
    <script src="../../js/common.js"></script>

    <script>
        layui.config({
            base: '/layui/extend/'
        }).extend({
            formSelects: 'formSelects-v4'
        }).use(['form', 'layer', 'formSelects', 'dtree'], function () {
            $ = layui.jquery;
            var form = layui.form
                , layer = layui.layer
                , formSelects = layui.formSelects
                , dtree = layui.dtree;

            // dtree.renderSelect({
            //     elem: "#deptTree",
            //     url: "/data/dept/tree.json",
            //     dataStyle: "layuiStyle",
            //     width: "100%",
            //     method: "GET",
            //     dot: false,
            //     accordion: true,
            //     menubar: true,
            //     response: {
            //         statusCode: 0,
            //         message: "msg",
            //         treeId: "id",
            //         parentId: "parentId",
            //         title: "name"
            //     }
            // });
            //
            // dtree.on("node('deptTree')" ,function(obj){
            //     $("#deptId").val(obj.param.nodeId);
            // });


            form.on('submit(search)', function (form) {
                // form.field.role = formSelects.value('role-select', 'val');

                var a = document.getElementsByName("sex");
                var sexd = 0;
                for(var   i=0;   i<a.length;   i++)    {
                    if(a[i].checked){
                        sexd = a[i].value
                    }
                }
                console.log("aadads"+form);
                $.ajax({
                    url: "/visiter/addV/",
                    type: 'post',
                    data: {name:$("#name").val(),age:$("#age").val(),account:$("#account").val(),sex:sexd,password:$("#password").val()},
                    dataType: "json",
                    async: false,
                    success: function (data) {
                        if (data.code == '201') {
                            layer.msg("失败", {icon: 5});//失败的表情
                            return;
                        } else if (data.code == '0') {
                            layer.msg("成功", {
                                icon: 6,//成功的表情
                                time: 1000 //1秒关闭（如果不配置，默认是3秒）
                            }, function () {
                                location.reload();
                            })
                        };
                        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                        parent.layer.close(index); //再执行关闭
                    }
                });
                return false;
            });
        });
    </script>

</body>
</html>